home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / Mail / def.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-08  |  8.7 KB  |  306 lines

  1. /*
  2.  * Copyright (c) 1980 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that the above copyright notice and this paragraph are
  7.  * duplicated in all such forms and that any documentation,
  8.  * advertising materials, and other materials related to such
  9.  * distribution and use acknowledge that the software was developed
  10.  * by the University of California, Berkeley.  The name of the
  11.  * University may not be used to endorse or promote products derived
  12.  * from this software without specific prior written permission.
  13.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  14.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  15.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  16.  *
  17.  *    @(#)def.h    5.18 (Berkeley) 8/17/88
  18.  */
  19.  
  20. #include <sys/param.h>        /* includes <sys/types.h> */
  21. #include <sys/signal.h>
  22. #include <stdio.h>
  23. #include <sgtty.h>
  24. #include <ctype.h>
  25. #include <strings.h>
  26. #include "local.h"
  27.  
  28. /*
  29.  * Mail -- a mail program
  30.  *
  31.  * Author: Kurt Shoens (UCB) March 25, 1978
  32.  */
  33.  
  34.  
  35. #define    ESCAPE        '~'        /* Default escape for sending */
  36. #define    NMLSIZE        1024        /* max names in a message list */
  37. #define    PATHSIZE    MAXPATHLEN    /* Size of pathnames throughout */
  38. #define    HSHSIZE        59        /* Hash size for aliases and vars */
  39. #define    LINESIZE    BUFSIZ        /* max readable line width */
  40. #define    STRINGSIZE    ((unsigned) 128)/* Dynamic allocation units */
  41. #define    MAXARGC        1024        /* Maximum list of raw strings */
  42. #define    NOSTR        ((char *) 0)    /* Null string pointer */
  43. #define    MAXEXP        25        /* Maximum expansion of aliases */
  44.  
  45. #define    equal(a, b)    (strcmp(a,b)==0)/* A nice function to string compare */
  46.  
  47. struct message {
  48.     short    m_flag;            /* flags, see below */
  49.     short    m_block;        /* block number of this message */
  50.     short    m_offset;        /* offset in block of message */
  51.     long    m_size;            /* Bytes in the message */
  52.     short    m_lines;        /* Lines in the message */
  53. };
  54.  
  55. /*
  56.  * flag bits.
  57.  */
  58.  
  59. #define    MUSED        (1<<0)        /* entry is used, but this bit isn't */
  60. #define    MDELETED    (1<<1)        /* entry has been deleted */
  61. #define    MSAVED        (1<<2)        /* entry has been saved */
  62. #define    MTOUCH        (1<<3)        /* entry has been noticed */
  63. #define    MPRESERVE    (1<<4)        /* keep entry in sys mailbox */
  64. #define    MMARK        (1<<5)        /* message is marked! */
  65. #define    MODIFY        (1<<6)        /* message has been modified */
  66. #define    MNEW        (1<<7)        /* message has never been seen */
  67. #define    MREAD        (1<<8)        /* message has been read sometime. */
  68. #define    MSTATUS        (1<<9)        /* message status has changed */
  69. #define    MBOX        (1<<10)        /* Send this to mbox, regardless */
  70.  
  71. /*
  72.  * Given a file address, determine the block number it represents.
  73.  */
  74. #define blockof(off)            ((int) ((off) / 4096))
  75. #define offsetof(off)            ((int) ((off) % 4096))
  76. #define positionof(block, offset)    ((off_t)(block) * 4096 + (offset))
  77.  
  78. /*
  79.  * Format of the command description table.
  80.  * The actual table is declared and initialized
  81.  * in lex.c
  82.  */
  83.  
  84. struct cmd {
  85.     char    *c_name;        /* Name of command */
  86.     int    (*c_func)();        /* Implementor of the command */
  87.     short    c_argtype;        /* Type of arglist (see below) */
  88.     short    c_msgflag;        /* Required flags of messages */
  89.     short    c_msgmask;        /* Relevant flags of messages */
  90. };
  91.  
  92. /* Yechh, can't initialize unions */
  93.  
  94. #define    c_minargs c_msgflag        /* Minimum argcount for RAWLIST */
  95. #define    c_maxargs c_msgmask        /* Max argcount for RAWLIST */
  96.  
  97. /*
  98.  * Argument types.
  99.  */
  100.  
  101. #define    MSGLIST     0        /* Message list type */
  102. #define    STRLIST     1        /* A pure string */
  103. #define    RAWLIST     2        /* Shell string list */
  104. #define    NOLIST     3        /* Just plain 0 */
  105. #define    NDMLIST     4        /* Message list, no defaults */
  106.  
  107. #define    P    040        /* Autoprint dot after command */
  108. #define    I    0100        /* Interactive command bit */
  109. #define    M    0200        /* Legal from send mode bit */
  110. #define    W    0400        /* Illegal when read only bit */
  111. #define    F    01000        /* Is a conditional command */
  112. #define    T    02000        /* Is a transparent command */
  113. #define    R    04000        /* Cannot be called from collect */
  114.  
  115. /*
  116.  * Oft-used mask values
  117.  */
  118.  
  119. #define    MMNORM        (MDELETED|MSAVED)/* Look at both save and delete bits */
  120. #define    MMNDEL        MDELETED    /* Look only at deleted bit */
  121.  
  122. /*
  123.  * Structure used to return a break down of a head
  124.  * line (hats off to Bill Joy!)
  125.  */
  126.  
  127. struct headline {
  128.     char    *l_from;    /* The name of the sender */
  129.     char    *l_tty;        /* His tty string (if any) */
  130.     char    *l_date;    /* The entire date string */
  131. };
  132.  
  133. #define    GTO    1        /* Grab To: line */
  134. #define    GSUBJECT 2        /* Likewise, Subject: line */
  135. #define    GCC    4        /* And the Cc: line */
  136. #define    GBCC    8        /* And also the Bcc: line */
  137. #define    GMASK    (GTO|GSUBJECT|GCC|GBCC)
  138.                 /* Mask of places from whence */
  139.  
  140. #define    GNL    16        /* Print blank line after */
  141. #define    GDEL    32        /* Entity removed from list */
  142. #define    GCOMMA    64        /* detract puts in commas */
  143.  
  144. /*
  145.  * Structure used to pass about the current
  146.  * state of the user-typed message header.
  147.  */
  148.  
  149. struct header {
  150.     struct name *h_to;        /* Dynamic "To:" string */
  151.     char *h_subject;        /* Subject string */
  152.     struct name *h_cc;        /* Carbon copies string */
  153.     struct name *h_bcc;        /* Blind carbon copies */
  154.     struct name *h_smopts;        /* Sendmail options */
  155. };
  156.  
  157. /*
  158.  * Structure of namelist nodes used in processing
  159.  * the recipients of mail and aliases and all that
  160.  * kind of stuff.
  161.  */
  162.  
  163. struct name {
  164.     struct    name *n_flink;        /* Forward link in list. */
  165.     struct    name *n_blink;        /* Backward list link */
  166.     short    n_type;            /* From which list it came */
  167.     char    *n_name;        /* This fella's name */
  168. };
  169.  
  170. /*
  171.  * Structure of a variable node.  All variables are
  172.  * kept on a singly-linked list of these, rooted by
  173.  * "variables"
  174.  */
  175.  
  176. struct var {
  177.     struct    var *v_link;        /* Forward link to next variable */
  178.     char    *v_name;        /* The variable's name */
  179.     char    *v_value;        /* And it's current value */
  180. };
  181.  
  182. struct group {
  183.     struct    group *ge_link;        /* Next person in this group */
  184.     char    *ge_name;        /* This person's user name */
  185. };
  186.  
  187. struct grouphead {
  188.     struct    grouphead *g_link;    /* Next grouphead in list */
  189.     char    *g_name;        /* Name of this group */
  190.     struct    group *g_list;        /* Users in group. */
  191. };
  192.  
  193. #define    NIL    ((struct name *) 0)    /* The nil pointer for namelists */
  194. #define    NONE    ((struct cmd *) 0)    /* The nil pointer to command tab */
  195. #define    NOVAR    ((struct var *) 0)    /* The nil pointer to variables */
  196. #define    NOGRP    ((struct grouphead *) 0)/* The nil grouphead pointer */
  197. #define    NOGE    ((struct group *) 0)    /* The nil group pointer */
  198.  
  199. /*
  200.  * Structure of the hash table of ignored header fields
  201.  */
  202. struct ignoretab {
  203.     int i_count;            /* Number of entries */
  204.     struct ignore {
  205.         struct ignore *i_link;    /* Next ignored field in bucket */
  206.         char *i_field;        /* This ignored field */
  207.     } *i_head[HSHSIZE];
  208. };
  209.  
  210. /*
  211.  * Token values returned by the scanner used for argument lists.
  212.  * Also, sizes of scanner-related things.
  213.  */
  214.  
  215. #define    TEOL    0            /* End of the command line */
  216. #define    TNUMBER    1            /* A message number */
  217. #define    TDASH    2            /* A simple dash */
  218. #define    TSTRING    3            /* A string (possibly containing -) */
  219. #define    TDOT    4            /* A "." */
  220. #define    TUP    5            /* An "^" */
  221. #define    TDOLLAR    6            /* A "$" */
  222. #define    TSTAR    7            /* A "*" */
  223. #define    TOPEN    8            /* An '(' */
  224. #define    TCLOSE    9            /* A ')' */
  225. #define TPLUS    10            /* A '+' */
  226. #define TERROR    11            /* A lexical error */
  227.  
  228. #define    REGDEP    2            /* Maximum regret depth. */
  229. #define    STRINGLEN    1024        /* Maximum length of string token */
  230.  
  231. /*
  232.  * Constants for conditional commands.  These describe whether
  233.  * we should be executing stuff or not.
  234.  */
  235.  
  236. #define    CANY        0        /* Execute in send or receive mode */
  237. #define    CRCV        1        /* Execute in receive mode only */
  238. #define    CSEND        2        /* Execute in send mode only */
  239.  
  240. /*
  241.  * Kludges to handle the change from setexit / reset to setjmp / longjmp
  242.  */
  243.  
  244. #define    setexit()    setjmp(srbuf)
  245. #define    reset(x)    longjmp(srbuf, x)
  246.  
  247. /*
  248.  * Truncate a file to the last character written. This is
  249.  * useful just before closing an old file that was opened
  250.  * for read/write.
  251.  */
  252. #define trunc(stream)    ftruncate(fileno(stream), (long) ftell(stream))
  253.  
  254. /*
  255.  * Forward declarations of routine types to keep lint and cc happy.
  256.  */
  257.  
  258. FILE    *Fdopen();
  259. FILE    *Popen();
  260. FILE    *collect();
  261. FILE    *infix();
  262. FILE    *run_editor();
  263. FILE    *setinput();
  264. char    **unpack();
  265. char    *calloc();
  266. char    *copy();
  267. char    *copyin();
  268. char    *detract();
  269. char    *expand();
  270. char    *getdeadletter();
  271. char    *gets();
  272. char    *hfield();
  273. char    *name1();
  274. char    *nameof();
  275. char    *nextword();
  276. char    *getenv();
  277. char    *getname();
  278. char    *fgets();
  279. char    *ishfield();
  280. char    *malloc();
  281. char    *mktemp();
  282. char    *readtty();
  283. char    *reedit();
  284. char    *salloc();
  285. char    *savestr();
  286. char    *skin();
  287. char    *snarf();
  288. char    *username();
  289. char    *value();
  290. char    *vcopy();
  291. char    *yankword();
  292. off_t    fsize();
  293. uid_t    getuid();
  294. struct    cmd    *lex();
  295. struct    grouphead    *findgroup();
  296. struct    name    *nalloc();
  297. struct    name    *cat();
  298. struct    name    *delname();
  299. struct    name    *elide();
  300. struct    name    *extract();
  301. struct    name    *gexpand();
  302. struct    name    *outof();
  303. struct    name    *put();
  304. struct    name    *usermap();
  305. struct    var    *lookup();
  306.